﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VipSys.SystemEntity;
using VipSys.Common.Library;
using System.Xml;

namespace VipSys.DataLayer
{
    public class ComboAccess
    {
        public static readonly ComboAccess Instance = new ComboAccess();
        private XMLBase m_XmlBase;
        public ComboAccess()
        {
            m_XmlBase = new XMLBase(SystemParam.Instance.WorkPath + "\\SystemConfig.xml");
        }
        public short GetRoleTypes(ref List<SysCombo> lstRoleTypes)
        {
            lstRoleTypes.Clear();
            XmlNodeList xmlNodeList = this.m_XmlBase.SelectNodeList(SystemData.XmlConfigItem.Roletype);
            foreach (XmlNode node in xmlNodeList)
            {
                SysCombo roletype = new SysCombo();
                roletype.Value = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Value);
                roletype.Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                lstRoleTypes.Add(roletype);
            }
            return SystemData.ReturnValue.OK;
        }
        public short GetPlaceTypes(ref List<SysCombo> lstPlaceTypes)
        {
            lstPlaceTypes.Clear();
            XmlNodeList xmlNodeList = this.m_XmlBase.SelectNodeList(SystemData.XmlConfigItem.Placetype);
            foreach (XmlNode node in xmlNodeList)
            {
                SysCombo placetype = new SysCombo();
                placetype.Value = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Value);
                placetype.Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                lstPlaceTypes.Add(placetype);
            }
            return SystemData.ReturnValue.OK;
        }
        public short GetGenders(ref List<SysCombo> lstGenders)
        {
            lstGenders.Clear();
            XmlNodeList xmlNodeList = this.m_XmlBase.SelectNodeList(SystemData.XmlConfigItem.Gender);
            foreach (XmlNode node in xmlNodeList)
            {
                SysCombo roletype = new SysCombo();
                roletype.Value = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Value);
                roletype.Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                lstGenders.Add(roletype);
            }
            return SystemData.ReturnValue.OK;
        }
        public short GetTemplates(ref List<SysCombo> lstTemplates)
        {
            if (lstTemplates == null)
                lstTemplates = new List<SysCombo>();
            lstTemplates.Clear();
            XmlNodeList xmlNodeList = this.m_XmlBase.SelectNodeList(SystemData.XmlConfigItem.Template);
            foreach (XmlNode node in xmlNodeList)
            {
                SysCombo roletype = new SysCombo();
                roletype.Value = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Value);
                roletype.Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                lstTemplates.Add(roletype);
            }
            return SystemData.ReturnValue.OK;
        }
        public short GetTemplate(string szName, ref SysCombo template)
        {
            if (template == null)
                template = new SysCombo();
            if (string.IsNullOrEmpty(szName))
            {
                return SystemData.ReturnValue.PARAM_ERROR;
            }
            XmlNodeList xmlNodeList = this.m_XmlBase.SelectNodeList(SystemData.XmlConfigItem.Template);
            foreach (XmlNode node in xmlNodeList)
            {
                string Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                if (Name == szName)
                {
                    template.Value = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Value);
                    template.Name = this.m_XmlBase.ReadXmlNode(node, SystemData.XmlCombo.Name);
                }
            }
            return SystemData.ReturnValue.OK;
        }
    }
}
